package servlet.article;

import dao.ArticleDao;
import entity.Article;
import util.GetParamToClass;
import util.R;
import util.ResposeUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DeleteServlet extends HttpServlet {
    ArticleDao articleDao = new ArticleDao();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Article article = (Article) GetParamToClass.setObjectFiled(req,Article.class);
        int insert = articleDao.delete(article.getId());
        R r = null;
        if (insert>0) {
            r =new R(R.CODE_SUCCESS, null,R.MSG_SUCCESS);
        } else {
            r =new R(R.CODE_ERR, null,R.MSG_ERR);
        }
        ResposeUtil.write(r ,resp);
    }
}
